﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Xml.Linq;
using System.Linq;

namespace Microsoft.Office.OneNote
{
    [OneNoteXmlElement("Title")]
    public sealed class OneNotePageTitle : OneNoteObject, IOneNoteObjectWithChildren
    {
        internal static readonly OneNoteProperty StyleProperty = OneNoteProperty.Register(
            "style", typeof(String), typeof(OneNotePageTitle));

        internal static readonly OneNoteProperty LanguageProperty = OneNoteProperty.Register(
            "lang", typeof(CultureInfo), typeof(OneNotePageTitle));

        private readonly OneNotePageObjectStorage _elements = new OneNotePageObjectStorage();

        public String Style
        {
            get { return GetValue<String>(StyleProperty); }
            set { SetValue(StyleProperty, value); }
        }

        public CultureInfo Language
        {
            get { return GetValue<CultureInfo>(LanguageProperty); }
            set { SetValue(LanguageProperty, value); }
        }

        public OneNoteOutlineElement OutlineElement
        {
            get 
            { 
                return _elements.OfType<OneNoteOutlineElement>().First(); 
            }

        }

        void IOneNoteObjectWithChildren.UpdateFrom(IEnumerable<XElement> elements)
        {
            _elements.UpdateFrom(elements);
        }
    }
}
